package com.chatsimple.netty.task.usecase

import com.chatsimple.netty.task.RequestHandler
import com.google.protobuf.ByteString
import com.google.protobuf.Message
import com.ly.data.FuncProto
import com.ly.data.FuncProto.Client


class GetClientsInfoUseCase(private val requestHandler: RequestHandler) : UseCase {
    override fun handle(param: ByteString): Message? {
        return FuncProto.ClientList.newBuilder()
            .addAllClients(requestHandler.clients.map {
                val clientId = it.key
                val host = it.value.get()?.remoteAddress()
                Client.newBuilder()
                    .setClientId(clientId)
                    .setHost(host?.toString() ?: "未知地址")
                    .build()
            })
            .setTimestamp(System.currentTimeMillis())
            .build()
    }


}